<?php
namespace BLL\DataModel;

/**
 * Description of DataItemDescription
 *
 * schema of a field of node
 * 
 * @author David Wu
 */
class DataItemDescription extends DataDescription {

    /**
     * The data type of this item.
     *
     * @var string DataType
     */
    public $dataType = DataType::String;
    
    
    /**
     * The data length of this item.
     *
     * @var int
     */
    public $dataLen = 0;

    /**
     * The field of this item.
     *
     * @var string
     */
    public $fieldName = null;

    /**
     * Key field of the node?
     * true: yes
     * false: no
     *
     * @var bool
     */
    public $uniqueGroup = null;
    
    /**
     * Default value of this item
     * true: yes
     * false: no
     *
     * @var object
     */
    public $intiValue = null;
    
    public $jsonAttribute = false;
    
    public $jsonValueItem =null;

    public $jsonSpecial = null;

    public $jsonSkipWhenEqual = null;

    /**
     * Construct method

     * @param string $name "config file nmae"
     * 
     */
    function __construct($_jsonObject){
        return $this->LoadFromJSON($_jsonObject);
    }
    
    /**
     * Load Item Schema from JSON Object

     * @param JSON $_jsonObject
     * 
     */
    protected function LoadFromJSON($_jsonObject){

        $this->LoadFromJSONObject($_jsonObject);
        
        if(isset($_jsonObject->dataType)){
            $this->dataType = DataType::createByName($_jsonObject->dataType);
        }
        $this->readAttrFromJSon( $_jsonObject, "fieldName",  DataType::String, $this->name);
        $this->readAttrFromJSon( $_jsonObject, "dataLen",  DataType::Int);
        $this->readAttrFromJSon( $_jsonObject, "uniqueGroup",  DataType::String);
        $this->readAttrFromJSon( $_jsonObject, "intiValue", $this->dataType);
        $this->readAttrFromJSon( $_jsonObject, "jsonAttribute",  DataType::String );
        $this->readAttrFromJSon( $_jsonObject, "jsonSpecial",  DataType::String );
        $this->readAttrFromJSon( $_jsonObject, "jsonSkipWhenEqual",  $this->dataType );
        if($this->jsonAttribute){
            $this->uniqueGroup = $this->name; 
        }
        if($this->uniqueGroup ){
            $this->isNecessary = true; 
        }
        $this->readAttrFromJSon( $_jsonObject, "jsonValueItem",  DataType::String , $this->name);
    }

}


